import { World } from '@ecs/index'

/**
 * 获取世界实例中存储的业务变量
 * @param world 世界实例
 * @returns 业务变量
 */
export function getWorldData(world: World) {
  const canvas = world.data.canvas as HTMLCanvasElement
  const map = world.data.map as Map<string, unknown>
  const isGameOver = world.data.isGameOver as boolean
  const speed = world.data.speed as number
  const gap = world.data.gap as number
  const sprites = map.get('sprites') as HTMLImageElement
  const spritesData = map.get('spritesData') as {
    [key: string]: {
      sx: number
      sy: number
      sw: number
      sh: number
    }
  }
  return { canvas, map, isGameOver, speed, gap, sprites, spritesData }
}
